package com.aaa.member.util;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.IOException;

/**
 * @fileName:PoiRead
 * @description:
 * @author:李铎
 * @createTime:2020/11/19 16:23
 * @version:1.0.0
 */

public class PoiRead {
    public static void main(String[] args) throws IOException {
        //获取工作簿对象
        XSSFWorkbook Workbook = new XSSFWorkbook("D:\\Poi测试\\车辆信息.xlsx");
        //获取工作表
        XSSFSheet sheet = Workbook.getSheetAt(0);
        //获取行
        /*for (Row row : sheet){
            //获取单元格
            for (Cell cell : row){
                String value =cell.getStringCellValue();
                System.out.println(value);
            }
        }*/

        //开始索引 0 结束索引
        int lastRowNum = sheet.getLastRowNum();
        System.out.println(lastRowNum);
        for (int i = 0; i <= lastRowNum; i++) {
            XSSFRow row = sheet.getRow(i);
            if (row != null) {
                //
                short cellNum = row.getLastCellNum();
                for (int j = 0; j <= cellNum; j++) {
                    XSSFCell cell = row.getCell(j);
                    if (cell != null) {
                        String stringCellValue = cell.getStringCellValue();
                        System.out.println(stringCellValue);
                    }

                }
            }

        }
        //释放资源
        Workbook.close();


    }
}
